# Various helper methods I didn't create seperate classes for for whatever reason

import libtcodpy as libtcod
from GameObject import Fighter
from Player import Player
import Messages
import Map

class Helper:
    @staticmethod
    def player_death(gamestate, player):
        Messages.message('You died! Press F1 for a new game.', libtcod.red)
        player.gamestate.game_state = 'dead'
        player.char = '%'
        player.color = libtcod.dark_red
        
    @staticmethod
    def monster_death(gamestate, monster):
        Messages.message(monster.name + ' is dead!', libtcod.red)
        monster.char = '%'
        monster.color = libtcod.dark_red
        monster.blocks = False
        monster.fighter = None
        monster.ai = None
        monster.name = 'remains of ' + monster.name
        monster.send_to_back()
        
    @staticmethod
    def potion(gamestate, player):
        Messages.message("You use the potion and recover some hp.")
        player.fighter.heal(20)
        
    @staticmethod
    def gen_new_map(gamestate):
        fighter_component = Fighter(hp=30, defense=2, power=5, death_func=Helper.player_death)
        gamestate.player = Player(gamestate, gamestate.SCREEN_WIDTH/2, gamestate.SCREEN_HEIGHT/2, 
                             '@', "Player", libtcod.white, blocks=True, 
                             fighter=fighter_component)
        gamestate.game_objects = [gamestate.player]
        gamestate.map = Map.Map(gamestate)
        gamestate.fov_map = libtcod.map_new(gamestate.map.MAP_WIDTH, gamestate.map.MAP_HEIGHT)
        
        for y in range(gamestate.map.MAP_HEIGHT):
            for x in range(gamestate.map.MAP_WIDTH):
                libtcod.map_set_properties(gamestate.fov_map, x, y, 
                                           not gamestate.map.map[x][y].blocked, 
                                           not gamestate.map.map[x][y].block_sight)
        
        gamestate.fov_recompute = True
        print 'Generated new map.'
        gamestate.player.move_or_attack(0,-1)
        gamestate.game_state = 'playing'
        